package com.tangye.massageshop.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tangye.massageshop.repository.ShopRepository;
import com.tangye.massageshop.entity.ShopEntity;
import com.tangye.massageshop.mapper.ShopMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShopRepositoryImpl implements ShopRepository {
    @Resource
    private ShopMapper shopMapper;
    @Override
    public List<ShopEntity> selectShopPage(ShopEntity shop) {
        QueryWrapper<ShopEntity> qw = new QueryWrapper<>();
        qw.eq("company_id", shop.getCompanyId());
        qw.eq("shop_id", shop.getShopId());
        if (StringUtils.isNotBlank(shop.getShopName())) {
            qw.eq("shop_name", shop.getShopName());
        }
        Page<ShopEntity> page = new Page<>(shop.getPageNum(), shop.getPageSize());
        Page<ShopEntity> resultPage = shopMapper.selectPage(page, qw);
        return resultPage.getRecords();
    }

    @Override
    public ShopEntity selectByName(String shopName) {
        QueryWrapper<ShopEntity> qw = new QueryWrapper<>();
        qw.eq("shop_name", shopName);
        return shopMapper.selectOne(qw);
    }
}
